local skel = fk.CreateSkill {
  name = "lb__fushi",
  max_branches_use_time = function(self, player)
    local room = Fk:currentRoom()
    local list = {}
    for _, to in ipairs(room.players) do
      list[tostring(to.id)] = { [Player.HistoryGame] = 1 }
    end
    return list
  end
}

Fk:loadTranslationTable {
  ["lb__fushi"] = "负世",
  --[":lb__fushi"] = "<b>锁定技</b>，当其他角色首次受到致命伤害时，若为属性伤害，将此伤害转移给你，然后你使用【杀】的次数上限+1。",
  --8.30
  [":lb__fushi"] = "每名角色限一次，当其他角色受到致命伤害时，你可以将此伤害转移给你，然后你使用【杀】的次数上限+1。",

  ["#lb__fushi"] = "负世：你可以将 %dest 受到的%arg点%arg2伤害转移给你，然后你使用【杀】的次数上限+1",

  ["@[player]lb__fushi"] = "负世",

  ["$lb__fushi1"] = "无妨，我会再次押上一切。",
  ["$lb__fushi2"] = "不能让大家失望！",
  ["$lb__fushi3"] = "以血，淬火！",
  ["$lb__fushi4"] = "此身的火焰，还不够猛烈。",
}

skel:addEffect(fk.DetermineDamageInflicted, {
  mute = true,
  priority = 0.1, --太牛马了
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target ~= player and data.damage >= (target.hp + target.shield)
        and skel:withinBranchTimesLimit(player, tostring(target.id), Player.HistoryGame)
    --[[
    and #player.room.logic:getEventsOfScope(GameEvent.Dying,1,function (e)
      local dying = e.data
      return dying.who == target and dying.damage ~= nil
    end,Player.HistoryGame) == 0
    --]]
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      { skill_name = skel.name, prompt = "#lb__fushi::" ..
      target.id .. ":" .. data.damage .. ":" .. Fk:getDamageNatureName(data.damageType), })
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, tostring(target.id))
    local room = player.room
    local audio = math.random(1, 2)
    if player:usedSkillTimes("lb__fenxiao", Player.HistoryGame) > 0 then
      audio = audio + 2
    end
    room:notifySkillInvoked(player, skel.name, "masochism", { target })
    player:broadcastSkillInvoke(skel.name, audio)
    local n = data.damage
    room:addTableMarkIfNeed(player, "lb__fushi-round", target.id)
    room:addTableMarkIfNeed(player, "@[player]lb__fushi", target.id) -- 8.30
    data:preventDamage()
    if not player.dead then
      room:damage {
        from = data.from,
        to = player,
        damage = n,
        damageType = data.damageType,
        skillName = data.skillName,
        chain = data.chain,
        card = data.card,
      }
    end
  end,
})

skel:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope, card, to)
    if player:hasSkill(skel.name) and card and card.trueName == "slash" and scope == Player.HistoryPhase then
      return #player:getTableMark("@[player]lb__fushi")
    end
  end
})

skel:addAcquireEffect(function(self, player, is_start)
  local room = player.room
  local list = {}
  for _, to in ipairs(room.players) do
    if not skel:withinBranchTimesLimit(player, tostring(to.id), Player.HistoryGame) then
      table.insert(list, to.id)
    end
  end
  player.room:setPlayerMark(player, "@[player]lb__fushi", #list > 0 and list or 0 )
end)

skel:addLoseEffect(function(self, player, is_death)
  local room = player.room
  room:setPlayerMark(player, "@[player]lb__fushi", 0)
end)

return skel